package com.horoscope.astrology.zodiac.signs.free

import android.os.Bundle
import android.view.View
import com.horoscope.astrology.zodiac.signs.free.activity.Base2Activity
import com.horoscope.astrology.zodiac.signs.free.utils.ad.ADConfig
import com.horoscope.astrology.zodiac.signs.free.utils.ad.NativeAdUtil
import com.horoscope.astrology.zodiac.signs.free.utils.ad.ad_business.ADNativeManager
import com.horoscope.astrology.zodiac.signs.free.utils.ad.ad_business.ADRewardManager
import kotlinx.android.synthetic.main.activity_main2.*
import kotlinx.android.synthetic.main.ad_layout.*


class Main2Activity : Base2Activity() {

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_main2)
    }

    fun loadAd(view: View) {
//        ADRewardManager.mInstance.rewardGroupRequest(0)
    }
    fun showAD(view: View) {
//        activityShowAd("插页")
//        isShowNativeAd()
//        val isShow = ADRewardManager.mInstance.showRewardAD(
//            "test", this@Main2Activity, 1, "test"
//        )
    }

    private fun isShowNativeAd() {
        val nativeAdBean = ADNativeManager.mInstance.getNativeAdBean("test")
        if (nativeAdBean != null) {
            include_ad.visibility = View.VISIBLE
            // 通过advertiser判断显示那个原生广告视图
            when (nativeAdBean.adInfo.advertiser) {
                ADConfig.FB -> {
                    native_ad_container.visibility = View.VISIBLE
                    ad_frame.visibility = View.GONE
                    if (nativeAdBean.facebookNativeAD != null) {
                        NativeAdUtil.inflateFacebookAd(
                            nativeAdBean.facebookNativeAD,
                            include_ad, "Custom_Meditm","Native_Home"
                        )
                        include_ad.visibility = View.VISIBLE
                    } else {
                        include_ad.visibility = View.GONE
                    }
                }
                ADConfig.ADMOB -> {
                    ad_frame.visibility = View.VISIBLE
                    native_ad_container.visibility = View.GONE
                    if (nativeAdBean.googleNativeAd != null) {
                        NativeAdUtil.inflateAdMobAd(
                            nativeAdBean.googleNativeAd!!,
                            include_ad,
                            "Custom_Meditm"
                        )
                        include_ad.visibility = View.VISIBLE
                    } else {
                        include_ad.visibility = View.GONE
                    }
                }
            }
        } else {
            include_ad.visibility = View.GONE
        }
    }
}
